<html>
<head>
	<title>CPAINT2 type testing</title>
	<script type="text/javascript" src="../../cpaint2.inc.compressed.js"></script>
	<script type="text/javascript">
	<!--
		var response_type = 'text';
		var cp = new cpaint();
		cp.set_response_type(response_type);

		function query() {
			cp.call('type.php', 'ping', response, document.getElementById('req').value);
		}
		
		function response(result) {
			if (response_type == 'text') {

				if (result !== '' 
          && String(result).search(/^\s+$/g) == -1 
          && !isNaN(result) 
          && isFinite(result)) {
          
					document.getElementById('ans').innerHTML = result + ' is a number and (' + result + ' + 42) == ' + (result+42);

				} else {
					document.getElementById('ans').innerHTML = result + ' is a string and (' + result + ' + 42) == ' + (result+42);
				}
				
			} else if (response_type == 'object') {
      
				if (String(result.type[0].data) !== '' 
          && String(result.type[0].data).search(/^\s+$/g) == -1 
          && !isNaN(result.type[0].data) 
          && isFinite(result.type[0].data)) {
          
					document.getElementById('ans').innerHTML = result.type[0].data + ' is a number and (' + result.type[0].data + ' + 42) == ' + (result.type[0].data+42);

				} else {
					document.getElementById('ans').innerHTML = result.type[0].data + ' is a string and (' + result.type[0].data + ' + 42) == ' + (result.type[0].data+42);
				}
			
      } else if (response_type == 'xml') {
				if (result.childNodes[0].firstChild
          && String(result.childNodes[0].firstChild.nodeValue) !== '' 
          && String(result.childNodes[0].firstChild.nodeValue).search(/^\s+$/g) == -1 
          && !isNaN(result.childNodes[0].firstChild.nodeValue) 
          && isFinite(result.childNodes[0].firstChild.nodeValue)) {
          
					document.getElementById('ans').innerHTML = result.childNodes[0].firstChild.nodeValue + ' is a number and (' + result.childNodes[0].firstChild.nodeValue + ' + 42) == ' + (result.childNodes[0].firstChild.nodeValue+42);

				} else if (result.childNodes[0].firstChild) {
					document.getElementById('ans').innerHTML = result.childNodes[0].firstChild.nodeValue + ' is a string and (' + result.childNodes[0].firstChild.nodeValue + ' + 42) == ' + (result.childNodes[0].firstChild.nodeValue+42);
        
        } else {
					document.getElementById('ans').innerHTML = 'no value was given';
				}
			}
		}
	//-->
	</script>
</head>
<body>
  This test displays the automatic type conversion for data that is sent from the backend to the frontend.<br />
  <br />
  All values you enter into that form are simply bounced back by the CPAINT backend, nothing is done with them.<br />
  The CPAINT frontend performs a type conversion on a by-value basis. So if a value is a valid integer or floating point number, it will convert it to a JavaScript number automatically for you.<br />
<br />
  This test displays this for you by adding the number 42 to the value that is returned: For numbers the values are added (1 + 42 == 43), for string values they are concatenated (one + 42 == one42).<br />
<br />
	<form action="#" onSubmit="return false">
		<input type="text" id="req" value="" />
		<input type="button" value="type test" onClick="query()" />
	</form>
	<div id="ans"></div>
</body>
</html>